@extends('layouts.file.app')
@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">文件管理</strong> /
                    <small>File Manage</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-title">名称</th>
                                <th class="table-type">类型</th>
                                <th class="table-author am-hide-sm-only">大小</th>
                                <th class="table-date am-hide-sm-only">时间</th>
                                <th class="table-set">操作</th>
                            </tr>
                            </thead>
                            <tbody>

                            @foreach($files as $file)
                                <tr>
                                    <td class="name"><a href="javascript:;">{{$file['name']}}</a></td>
                                    <td>{{$file['type']}}</td>
                                    <td class="am-hide-sm-only">{{$file['size']}}</td>
                                    <td class="am-hide-sm-only">{{$file['date']}}</td>
                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                @if($file['type'] == '目录文件')
                                                    <button class="am-btn am-btn-default am-btn-xs am-text-success">
                                                        <span class="am-icon-paper-plane"></span> 进入
                                                    </button>
                                                @elseif($file['type'] == '普通文件' && $file['is_image'] == false)
                                                    <a href="javascript:;" class="am-btn am-btn-default am-btn-xs am-text-secondary edit" data-am-modal="{target: '#edit-modal'}">
                                                        <span class="am-icon-pencil-square-o"></span> 编辑
                                                    </a>
                                                @endif
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </form>
                </div>

            </div>
        </div>

        <footer class="admin-content-footer">
            <hr>
            <p class="am-padding-left">© 2014 AllMobilize, Inc. Licensed under MIT license.</p>
        </footer>
    </div>

    <!--编辑模态框-->
    <div class="am-modal am-modal-no-btn" id="edit-modal">
        <div class="am-modal-dialog">
            <div class="am-modal-hd">编辑文件
                <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
            </div>

            <div class="am-u-sm-12 am-u-md-12">

                <form class="am-form">
                    <input type="hidden" id="old_name">
                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-4 am-text-right">
                            文件名称:
                        </div>
                        <div class="am-u-sm-4 am-u-md-8 am-u-end col-end">
                            <input type="text" id="edit_name">
                        </div>
                    </div>

                    <div class="am-g am-margin-top">
                        <div class="am-u-sm-4 am-u-md-4 am-text-right">
                            文件内容:
                        </div>
                        <div class="am-u-sm-4 am-u-md-8 am-u-end col-end">
                            <textarea id="edit_content" cols="30" rows="10"></textarea>
                        </div>
                    </div>

                    <div class="am-margin">
                        <button type="button" class="save_submit am-btn am-btn-primary am-radius">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

@endsection

@section('js')
    <script>
        $(function () {
            //编辑普通文件
            $('.edit').click(function () {
                var name = $(this).parents('td').siblings('.name').text();

                //设置值
                $("#edit_name").val(name);
                $("#old_name").val(name);

                //获取普通文件的内容并设置值
                $.get("/admin/system/file/edit?name=" + name, function (data) {
//                    console.log(data);
                    $("#edit_content").val(data.contents);
                })
            })


        })
    </script>
@endsection